#include<stdio.h>
#include<stdlib.h>
 
typedef struct node
{
    int data;
    struct node *next;
}node;
 
//创建链表,有头节点
struct node *creat_link(struct node *head)
{
    int num=0;//存储链表的值
    head=(struct node *)malloc(sizeof(struct node));
    head->next=NULL;
    struct node *tail=head;
    for(int i=1;i<=5;i++)
    {
        struct node *new=(struct node *)malloc(sizeof(struct node));
        scanf("%d",&num);     
        new->data=num;
        new->next=NULL;
        tail->next=new; 
        tail=new;
    }
    return head;
}
 
//输出链表
void show(struct node *head)
{
    head=head->next;
    while(head!=NULL)
    {
        printf("%d\t",head->data);
        head=head->next;
    }
    return ;
}
 
// 释放整个链表（包括头节点）
void list_free(node *list) {
    node *current = list->next;
    while (current != NULL) {
        node *temp = current;
        current = current->next;
        free(temp);
    }
}
 
 
int main(int argc, char const *argv[])
{
    struct  node *head;
    head=creat_link(head);
    show(head);
    list_free(head);
    return 0;
}


